//
//  EntryView.m
//  HDecoration
//
//  Created by koki on 15/9/29.
//  Copyright (c) 2015年 HDecoration. All rights reserved.
//

#import "EntryView.h"
#define kredColor [UIColor colorWithRed:0.9 green:0.29 blue:0.196 alpha:1]

@interface EntryView ()
@property  UILabel* kclable;
@property  UILabel* ddlable;
@property  UILabel* xylable;
@property  UIButton* tipBtn;
@property  GXButton* xqBtn;
@end
@implementation EntryView
@synthesize kclable,ddlable,xylable,tipBtn,xqBtn;

-(id)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self)
    {
        [self initUI];
        [self requestWorkInfo];
    }
    return self;
}

-(void)initUI
{
    DOImageView* bgView=[[DOImageView alloc] initWithFrame:self.bounds];
    bgView.imgURLStr=@"entryBg";
    [self addSubview:bgView];
    
    float rate=(self.width/320.0-1);
    float x=0;
    float y=200*(rate+1)-rate*109;
    CGRect rect=CGRectMake(x, y, self.width, (rate+1)*218);
    DOImageView* pictureView=[[DOImageView alloc] initWithFrame:rect];
    pictureView.imgURLStr=@"description";
    [self addSubview:pictureView];
    
    //向上添加
    //今日课程
    y=pictureView.top-30;
    x=(self.width-190)/2.0;
    GXButton*jrkcBtn=[GXButton buttonWithType:UIButtonTypeCustom];
    jrkcBtn.frame=CGRectMake(x,y, 190, 30);
    jrkcBtn.relayout=YES;
    jrkcBtn.userInteractionEnabled=NO;
    jrkcBtn.titleLabelFrame=CGRectMake(20, 0, 80, 30);
    jrkcBtn.imageViewFrame=CGRectMake(0, 8, 14, 14);
    jrkcBtn.titleLabel.font=[UIFont systemFontOfSize:16];
    [jrkcBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [jrkcBtn setTitle:@"今日课程:" forState:UIControlStateNormal];
    [jrkcBtn setImage:[UIImage imageNamed:@"entry_001"] forState:UIControlStateNormal];
    [self addSubview:jrkcBtn];
    
    x=jrkcBtn.left+100;
    rect=CGRectMake(x, y,self.width-x,30);
    kclable=[[UILabel alloc] initWithFrame:rect];
    kclable.textColor=kredColor;
    kclable.font=[UIFont boldSystemFontOfSize:19];
    [self addSubview:kclable];
    
    //今日订单
    y=jrkcBtn.top-30;
    x=jrkcBtn.left;
    GXButton*jrddBtn=[GXButton buttonWithType:UIButtonTypeCustom];
    jrddBtn.frame=CGRectMake(x,y, 190, 30);
    jrddBtn.relayout=YES;
    jrddBtn.userInteractionEnabled=NO;
    jrddBtn.titleLabelFrame=CGRectMake(20, 0, 80, 30);
    jrddBtn.imageViewFrame=CGRectMake(0, 8, 14, 14);
    jrddBtn.titleLabel.font=[UIFont systemFontOfSize:16];
    [jrddBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [jrddBtn setTitle:@"今日订单:" forState:UIControlStateNormal];
    [jrddBtn setImage:[UIImage imageNamed:@"entry_002"] forState:UIControlStateNormal];
    [self addSubview:jrddBtn];
    
    x=jrddBtn.left+100;
    rect=CGRectMake(x, y,self.width-x,30);
    ddlable=[[UILabel alloc] initWithFrame:rect];
    ddlable.textColor=kredColor;
    ddlable.font=[UIFont boldSystemFontOfSize:19];
    [self addSubview:ddlable];
    
    //在线学员
    y=jrddBtn.top-30;
    x=jrddBtn.left;
    GXButton*zxxyBtn=[GXButton buttonWithType:UIButtonTypeCustom];
    zxxyBtn.frame=CGRectMake(x,y, 190, 30);
    zxxyBtn.relayout=YES;
    zxxyBtn.userInteractionEnabled=NO;
    zxxyBtn.titleLabelFrame=CGRectMake(20, 0, 80, 30);
    zxxyBtn.imageViewFrame=CGRectMake(0, 8, 14, 14);
    zxxyBtn.titleLabel.font=[UIFont systemFontOfSize:16];
    [zxxyBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [zxxyBtn setTitle:@"在线学员:" forState:UIControlStateNormal];
    [zxxyBtn setImage:[UIImage imageNamed:@"entry_003"] forState:UIControlStateNormal];
    [self addSubview:zxxyBtn];
    
    x=zxxyBtn.left+100;
    rect=CGRectMake(x, y,self.width-x,30);
    xylable=[[UILabel alloc] initWithFrame:rect];
    xylable.textColor=kredColor;
    xylable.font=[UIFont boldSystemFontOfSize:19];
    [self addSubview:xylable];
    
    
    //星期
    y=zxxyBtn.top-60;
    x=(self.width-146)/2.0;
    xqBtn=[GXButton buttonWithType:UIButtonTypeCustom];
    xqBtn.frame=CGRectMake(x,y, 146, 50);
    xqBtn.relayout=YES;
    xqBtn.userInteractionEnabled=NO;
    xqBtn.titleLabelFrame=CGRectMake(0, 0, 146, 40);
    xqBtn.imageViewFrame=CGRectMake(0, 0, 146, 50);
    xqBtn.titleLabel.font=[UIFont boldSystemFontOfSize:19];
    xqBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
    [xqBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [xqBtn setImage:[UIImage imageNamed:@"entry_004"] forState:UIControlStateNormal];
    [self addSubview:xqBtn];
    
    //向下添加
    y=pictureView.bottom;
    rect=CGRectMake(0, y, self.width,20);
    UILabel* lable=[[UILabel alloc] initWithFrame:rect];
    lable.textAlignment=NSTextAlignmentCenter;
    lable.textColor=kredColor;
    lable.attributedText=[[NSAttributedString alloc] initWithString:@"祝你今天教学愉快" attributes:
                          @{NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleSingle]}];
    [self addSubview:lable];
    
    //添加确定按钮
    y=self.bottom-110*(rate+1);
    x=(self.width-220)/2.0;
    UIButton*okBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    okBtn.frame=CGRectMake(x,y,220, 40);
    okBtn.titleLabel.font=[UIFont boldSystemFontOfSize:16];
    okBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
    [okBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [okBtn setTitle:@"开始上班喽" forState:UIControlStateNormal];
    [okBtn setBackgroundImage:[UIImage imageNamed:@"entry_005"] forState:UIControlStateNormal];
    [okBtn addTarget:self action:@selector(okBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:okBtn];
    
    //添加数字提醒按钮
    y=okBtn.top-8;
    x=okBtn.right-20;
    tipBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    tipBtn.frame=CGRectMake(x,y,16, 16);
    tipBtn.titleLabel.font=[UIFont boldSystemFontOfSize:12];
    tipBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
    [tipBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tipBtn setBackgroundImage:[UIImage imageNamed:@"entry_006"] forState:UIControlStateNormal];
    [self addSubview:tipBtn];
}

-(void)okBtnAction
{
    [UIView animateWithDuration:0.2 animations:^{
        self.alpha=0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

-(void)setData:(HDWorkInfo *)data
{
    _data=data;
}


- (void)requestWorkInfo
{
    //待上班
    NSDictionary* params=@{
                           @"coach_id":netEngine.coachInfo.m_id,
                        };
    
    [netEngine RequesWorkWithTarget:self hudView:self Data:params];
}


-(void)requestWorkInfoSuccuss:(HDWorkInfo*)workInfo
{
    [tipBtn setTitle:workInfo.class_count forState:UIControlStateNormal];
    kclable.text=workInfo.class_count;
    ddlable.text=workInfo.order_count;
    xylable.text=workInfo.user_count;
    NSString* str=[NSString stringWithFormat:@"今日%@",workInfo.week];
   [xqBtn setTitle:str forState:UIControlStateNormal];
    
    //今日课程
    NSAttributedString* attrStr0=[[NSAttributedString alloc] initWithString:workInfo.class_count attributes:
                            @{NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleSingle],
                              NSFontAttributeName:[UIFont boldSystemFontOfSize:19],
                              NSForegroundColorAttributeName:kredColor
                              }];
    NSAttributedString* attrStr1=[[NSAttributedString alloc] initWithString:@" 个" attributes:
                                 @{
                                   NSFontAttributeName:[UIFont systemFontOfSize:15],
                                   NSForegroundColorAttributeName:[UIColor blackColor]
                                   }];
    NSMutableAttributedString* mutableStr=[[NSMutableAttributedString alloc] initWithAttributedString:attrStr0];
    [mutableStr appendAttributedString:attrStr1];
    kclable.attributedText=mutableStr;
    
    //今日订单
    NSAttributedString* attrStr2=[[NSAttributedString alloc] initWithString:workInfo.order_count attributes:
                                  @{NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleSingle],
                                    NSFontAttributeName:[UIFont boldSystemFontOfSize:19],
                                    NSForegroundColorAttributeName:kredColor
                                    }];
    NSMutableAttributedString* mutableStr1=[[NSMutableAttributedString alloc] initWithAttributedString:attrStr2];
    [mutableStr1 appendAttributedString:attrStr1];
    ddlable.attributedText=mutableStr1;
    
    //在线
    NSAttributedString* attrStr3=[[NSAttributedString alloc] initWithString:workInfo.user_count attributes:
                                  @{NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleSingle],
                                    NSFontAttributeName:[UIFont boldSystemFontOfSize:19],
                                    NSForegroundColorAttributeName:kredColor
                                    }];
    NSAttributedString* attrStr4=[[NSAttributedString alloc] initWithString:@" 位" attributes:
                                  @{
                                    NSFontAttributeName:[UIFont systemFontOfSize:15],
                                    NSForegroundColorAttributeName:[UIColor blackColor]
                                    }];
    NSMutableAttributedString* mutableStr2=[[NSMutableAttributedString alloc] initWithAttributedString:attrStr3];
    [mutableStr2 appendAttributedString:attrStr4];
    xylable.attributedText=mutableStr2;
    
}
@end
























